Version 4/061226 of Atmospheric Effects by Mikael Segercrantz begin here.

"A table-based way to add atmospheric effects to rooms, regions, things and scenes."


Part 1 - Generalia

Chapter 1(a) - Kinds of value

Section 1(a)1 - Scenic type

A scenic type is a kind of value.
The scenic types are full random, fully random, random and ordered.

Section 1(a)2 - Running type

A running type is a kind of value.
The running types are run once, once, run forever and forever.

Section 1(a)3 - Further type

A further type is a kind of value.
The further types are default and stopping.

Section 1(a)4 - Ignoring type

An ignoring type is a kind of value.
The ignoring types are ignore and do not ignore.

Section 1(a)5 - Shown type

A shown type is a kind of value.
The shown types are already shown and unshown.


Chapter 1(b) - Modifications

Section 1(b)1 - Room

A room has a table-name called scenic table.
The scenic table of a room is usually the Table of Default Atmospherics.

A room has an ignoring type called ignoring.
The ignoring of a room is usually do not ignore.

Section 1(b)2 - Region

A region has a table-name called scenic table.
The scenic table of a region is usually the Table of Default Atmospherics.

A region has an ignoring type called ignoring.
The ignoring of a region is usually do not ignore.

A region has a shown type called isshown.
The isshown of a region is usually unshown.

Section 1(b)3 - Things

A thing has a table-name called scenic table.
The scenic table of a thing is usually the Table of Default Atmospherics.

A thing has an ignoring type called ignoring.
The ignoring of a thing is usually do not ignore.


Chapter 1(c) - Global tables

Section 1(c)1 - Table of Default Atmospherics

Table of Default Atmospherics
during		initch		latch		aftcnt		curcnt		sctype		runtype		frtype		igtype		subtable
a scene		a number	a number	a number	a number	a scenic type	a running type	a further type	an ignoring type	a table-name

Section 1(c)2 - Table of Atmospheric Definition

Table of Atmospheric Definition
loci		ignoring			subtable
an object	an ignoring type		a table-name

Section 1(c)3 - Table of Default Messages

Table of Default Messages
used		message
a number	text

Section 1(c)4 - Table of Messages to Show

Table of Messages to Show
message
text
with 19 blank rows


Chapter 1(d) - Other globals

Section 1(d)1 - The empty region

The empty region is a region.


Part 2 - Initialization

Chapter 2(a) - Corrections

Section 2(a)1 - Correct synonyms

To correct synonyms:
	repeat with r running through rooms
	begin;
		correct synonyms of r;
	end repeat;
	repeat with r running through regions
	begin;
		correct synonyms of r;
	end repeat;
	repeat with r running through things
	begin;
		correct synonyms of r;
	end repeat.

Section 2(a)2 - Correct synonyms of

To correct synonyms of (r - an object):
	if r is a room or r is a region or r is a thing
	begin;
		repeat through the scenic table of r
		begin;
			if the scenic table of r is the Table of Default Atmospherics
			begin;
				change the runtype entry to run forever;
			end if;
			if the subtable entry is the Table of Default Messages, change the runtype entry to run forever;
			if the sctype entry is full random, change the sctype entry to fully random;
			if the runtype entry is once, change the runtype entry to run once;
			if the runtype entry is forever, change the runtype entry to run forever;
		end repeat;
	end if.
	

Chapter 2(b) - Initialization

Section 2(b)1 - Initializing from Table of Atmospheric Definition

To initialize from table:
	repeat through the Table of Atmospheric Definition
	begin;
		if the loci entry is a room or the loci entry is a region or the loci entry is a thing
		begin;
			change the scenic table of the loci entry to the subtable entry;
			change the ignoring of the loci entry to the ignoring entry;
		end if;
	end repeat.

Section 2(b)2 - Initializing the locations

To initialize the locations:
	repeat with r running through rooms
	begin;
		initialize the location r;
	end repeat;
	repeat with r running through regions
	begin;
		initialize the location r;
	end repeat;
	repeat with r running through things
	begin;
		initialize the location r;
	end repeat.

Section 2(b)3 - Initialize the location

To initialize the location (r - an object):
	if r is a room or r is a region or r is a thing
	begin;
		let tbl be the scenic table of r;
		repeat with n running from 1 to the number of rows in tbl
		begin;
			choose row n in tbl;
			if there is a subtable entry
			begin;
				if there is an initch entry
				begin;
				otherwise;
					change the initch entry to 100;
				end if;
				if there is a latch entry
				begin;
				otherwise;
					change the latch entry to the initch entry;
				end if;
				if there is an aftcnt entry
				begin;
				otherwise;
					change the aftcnt entry to 0;
				end if;
				if the aftcnt entry is less than 0, change the aftcnt entry to 0;
				change the curcnt entry to 0;
				if there is an sctype entry
				begin;
				otherwise;
					change the sctype entry to random;
				end if;
				if there is a runtype entry
				begin;
				otherwise;
					change the runtype entry to run forever;
				end if;
				if there is an frtype entry
				begin;
				otherwise;
					change the frtype entry to stopping;
				end if;
				if there is an igtype entry
				begin;
				otherwise;
					change the igtype entry to do not ignore;
				end if;
				if the subtable entry is the Table of Default Messages
				begin;
					change the frtype entry to stopping;
					change the runtype entry to run forever;
				end if;
				repeat through the subtable entry
				begin;
					change the used entry to 0;
				end repeat;
			end if;
		end repeat;
	end if.

Section 2(b)4 - When play begins

When play begins:
	initialize from table;
	initialize the locations;
	correct synonyms.


Part 3 - Decisions and counting

Chapter 3(a) - Counting

Section 3(a)1 - Number of used rows

To decide what number is the number of used rows in (tbl - a table-name):
	let count be 0;
	repeat through tbl
	begin;
		if there is a used entry
		begin;
			if the used entry is greater than 0, increase the count by 1;
		end if;
	end repeat;
	decide on count.

Section 3(a)2 - Number of free rows

To decide what number is the number of free rows in (tbl - a table-name):
	let count be 0;
	repeat through tbl
	begin;
		if there is a used entry
		begin;
			if the used entry is 0, increase the count by 1;
		end if;
	end repeat;
	decide on count.


Chapter 3(b) - Numerical decisions

Section 3(b)1 - Maximum number

To decide what number is the largest number in (tbl - a table-name):
	let current be 0;
	repeat through tbl
	begin;
		if there is a used entry
		begin;
			if the used entry is greater than current,
				change current to the used entry;
		end if;
	end repeat;
	decide on current.


Chapter 3(c) - Decisions

Section 3(c)1 - A scenic is shown

To decide whether a scenic with initch (ic - a number) latch (lc - a number) aftcnt (ac - a number) curcnt (cc - a number) is shown:
	if ac is 0
	begin;
		if a random chance of ic in 100 succeeds, decide yes;
		decide no;
	otherwise;
		if cc is less than ac
		begin;
			if a random chance of ic in 100 succeeds, decide yes;
			decide no;
		otherwise;
			if a random chance of lc in 100 succeeds, decide yes;
			decide no;
		end if;
	end if.


Part 4 - Saying

Chapter 4(a) - General

Section 4(a)1 - Display row

To display row (row number - a number) in (tbl - a table-name) running (runtype - a running type):
	let current row be 0;
	sort tbl in used order;
	repeat with i running from 1 to the number of rows in tbl
	begin;
		choose row i in tbl;
		if there is a message entry
		begin;
			if current row is less than row number,
				increase current row by 1;
			if current row is row number and the used entry is 0
			begin;
				increase current row by 1;
				let txt be the message entry;
				choose a blank row in the Table of Messages to Show;
				change the message entry to txt;
				choose row i in tbl;
				change the used entry to the turn count;
				if runtype is run once, blank out the whole row;
			end if;
		end if;
	end repeat.

Section 4(a)2 - Clean all messages

To clean all messages in (tbl - a table-name):
	repeat through tbl
	begin;
		change the used entry to 0;
	end repeat.


Chapter 4(b) - Rules for fully random messages

Section 4(b)1 - To say a fully random

To say a fully random scenic message of (tbl - a table-name) running (runtype - a running type):
	let row number be a random number between 1 and the number of filled rows in tbl;
	display row row number in tbl running runtype;
	clean all messages in tbl.


Chapter 4(c) - Rules for random messages

Section 4(c)1 - To say a random

To say a random scenic message of (tbl - a table-name) running (runtype - a running type):
	let current count be the number of free rows in tbl;
	let maximum be the largest number in tbl;
	let original count be current count;
	if current count is 0
	begin;
		clean messages of tbl with maximum;
		let current count be the number of filled rows in tbl minus 1;
		if the number of filled rows in tbl is 1
		begin;
			clean last message of tbl;
			let current count be the number of filled rows in tbl;
		end if;
	end if;
	let row number be a random number between 1 and current count;
	let current row be 0;
	display row row number in tbl running runtype;
	if the original count is 0 and the number of filled rows in tbl is greater than 0 and maximum is greater than 0
	begin;
		choose row with used of maximum in tbl;
		change the used entry to 0;
	end if.

Section 4(c)2 - Clean messages

To clean messages of (tbl - a table-name) with (maximum - a number):
	repeat through tbl
	begin;
		if the used entry is less than maximum,
			change the used entry to 0;
	end repeat.

Section 4(c)3 - Clean last message

To clean last message of (tbl - a table-name):
	clean all messages in tbl.


Chapter 4(d) - Rules for ordered messages

Section 4(d)1 - To say an ordered

To say an ordered scenic message of (tbl - a table-name) running (runtype - a running type):
	let current count be the number of free rows in tbl;
	let maximum be the largest number in tbl;
	let original count be current count;
	if current count is 0
	begin;
		let current count be 1;
		clean messages of tbl with maximum;
		if the number of filled rows in tbl is 1,
			clean last message of tbl;
	end if;
	display row 1 in tbl running runtype;
	if the original count is 0 and the number of filled rows in tbl is greater than 0 and maximum is greater than 0
	begin;
		choose row with used of maximum in tbl;
		change the used entry to 0;
	end if.


Part 5 - Common phrases for rooms, regions and things

Chapter 5(a) - Displaying

Section 5(a)1 - Display messages of

To display messages of (r - an object):
	if r is a room or r is a region or r is a thing
	begin;
		let tbl be the scenic table of r;
		let ign be 0;
		repeat with n running from 1 to the number of rows in tbl
		begin;
			choose row n in tbl;
			let doshow be 0;
			if there is a during entry
			begin;
				if the during entry is happening,
					change doshow to 1;
			otherwise;
				change doshow to 1;
			end if;
			if there is a subtable entry
			begin;
			otherwise;
				change doshow to 0;
			end if;
			if ign is 1, change doshow to 0;
			if doshow is 1
			begin;
				if a scenic with initch initch entry latch latch entry aftcnt aftcnt entry curcnt curcnt entry is shown
				begin;
					let cc be the curcnt entry;
					increase cc by 1;
					if cc is greater than the number of filled rows in tbl,
						change cc to the number of filled rows in tbl;
					change the curcnt entry to cc;
					let rtype be the runtype entry;
					let stbl be the subtable entry;
					let scenic be the sctype entry;
					if scenic is fully random,
						say a fully random scenic message of stbl running rtype;
					if scenic is random,
						say a random scenic message of the stbl running rtype;
					if scenic is ordered,
						say an ordered scenic message of stbl running rtype;
					choose row n in tbl;
					if the igtype entry is ignore, change ign to 1;
					if the number of filled rows in the subtable entry is 0 and the frtype entry is default
					begin;
						change the subtable entry to the Table of Default Messages;
						change the frtype entry to stopping;
						change the runtype entry to run forever;
					end if;
				end if;
			end if;  
		end repeat;
	end if.

Section 5(a)2 - Display all messages

To display all messages:
	let nummessages be the number of filled rows in the Table of Messages to Show;
	sort the Table of Messages to Show in random order;
	repeat through the Table of Messages to Show
	begin;
		say "[message entry] ";
		blank out the whole row;
	end repeat;
	if nummessages is greater than 0,
		say "[paragraph break]".


Part 6 - Rooms

Chapter 6(a) - Every turn in rooms

Section 6(a)1 - Check room messages

To check room messages:
	let shw be 1;
	repeat through the Table of Atmospheric Definition
	begin;
		if the ignoring entry is ignore
		begin;
			if the loci entry is a thing
			begin;
				if the player can see the loci entry, change shw to 0;
			end if;
		end if;
	end repeat;
	if shw is 1,
		display messages of location.


Part 7 - Regions

Chapter 7(a) - Every turn in regions

Section 7(a)1 - Check region messages

To check region messages:
	let shw be 1;
	repeat through the Table of Atmospheric Definition
	begin;
		if the ignoring entry is ignore
		begin;
			if the loci entry is a thing
			begin;
				if the player can see the loci entry, change shw to 0;
			otherwise;
				if the loci entry is a room
				begin;
					if in the loci entry, change shw to 0;
				end if;
			end if;
		end if;
	end repeat;
	if shw is 1
	begin;
		clean regions;
		let count be the number of located regions;
		repeat with n running from 1 to count
		begin;
			let the final region be the smallest unshown region;
			if the final region is not the empty region
			begin;
				display messages of the final region;
				change isshown of the final region to already shown;
			otherwise;
				change n to count;
			end if;
		end repeat;
	end if.

Section 7(a)2 - Clean regions

To clean regions:
	repeat with r running through regions
	begin;
		change isshown of r to unshown;
	end repeat;
	change isshown of the empty region to already shown.

Section 7(a)3 - The number of located regions

To decide what number is the number of located regions:
	let count be 0;
	repeat with r running through regions
	begin;
		if in r and isshown of r is unshown,
			increase count by 1;
	end repeat;
	decide on count.

Section 7(a)4 - The smallest unshown region

To decide which region is the smallest unshown region:
	let final region be the empty region;
	repeat with r running through regions
	begin;
		if final region is the empty region
		begin;
			if in r
			begin;
				if isshown of r is unshown
				begin;
					let final region be r;
				end if;
				repeat through the Table of Atmospheric Definition
				begin;
					if the loci entry is r and the ignoring entry is ignore
					begin;
						let final region be r;
					end if;
				end repeat;
			end if;
		end if;
	end repeat;
	repeat with r running through regions
	begin;
		if in r
		begin;
			if r is in the final region
			begin;
				if isshown of r is unshown
				begin;
					let final region be r;
				end if;
				repeat through the Table of Atmospheric Definition
				begin;
					if the loci entry is r and the ignoring entry is ignore
					begin;
						let final region be r;
					end if;
				end repeat;
			end if;
		end if;
	end repeat;
	if isshown of the final region is already shown
	begin;
		let final region be the empty region;
	end if;
	decide on the final region.


Part 8 - Things

Chapter 8(a) - Every turn in the presence of

Section 8(a)1 - Check thing messages

To check thing messages:
	repeat with t running through things
	begin;
		if the player can see t
		begin;
			display messages of t;
		end if;
	end repeat.


Part 9 - Overridables

Chapter 9(a) - Before reading a command

Section 9(a)1 - The scenic messaging rule

Before reading a command (this is the scenic messaging rule):
	correct synonyms;
	check thing messages;
	check room messages;
	check region messages;
	display all messages.


Atmospheric Effects end here.

---- DOCUMENTATION ----

*** VERSION NOTE ***

This version of the extension breaks compatibility with any previous version. It is highly recommended to upgrade all code using any previous version of Atmospheric Effects to use this version.

This version of Atmospheric Effects is a complete rewrite, containing almost all the features available in previous releases.

*** THE KINDS PROVIDED ***

This extension provides four kinds of value; a scenic type, a running type, a further type and an ignoring type.

The scenic types are
	* fully random (with full random as a synonym), displaying messages in a completely random order, without regard to if the message has been shown or not;
	* random, displaying messages in a constrained random order, so that each message in the table is shown once before any message may repeat; and
	* ordered, listing the messages in the same order they are defined in the table.

The running types are
	* run once (with once as a synonym), the messages of the table will show up only once; and
	* run forever (with forever as a synonym), the messages will loop once the table has been used, and if the scenic type is random, again in a random order (making sure the same message does not appear twice in a row).

The further types are
	* default, which changes to the Table of Default Messages once all the messages in the current table have been exhausted; and
	* stopping, which stops the current table once it has been exhausted and doesn't bring in a new source of messages.

The ignoring types are
	* ignore, which
		1) In the Atmospheric Definition table on things tells the extension to ignore rooms and regions (note that at the moment this means that even if the thing has ran out of messages, it forces the room and regions to be quiet whenever it is present);
		2) In the Atmospheric Definition table on rooms tells the extension to ignore regions;
		3) In the Atmospheric Definition table on regions tells the extension to ignore larger regions; and
		4) In the subtables of the Atmospheric Definition table tells the extension to ignore all lines after the current line in case a message was shown.
	and
	* do not ignore, which is the opposite of ignore.

For entries with a scenic type of fully random, the running type and the further type are completely ignored, and for entries with a running type of run forever, the further type is completely ignored.

*** THE TABLES USED ***

To use scenic effects in our games, we need to define the following table:

	Table of Atmospheric Definition (continued)
	loci		ignoring		subtable
	an object	an ignoring type	a table-name

The loci entry contains the name of the room or region for which to use the subtable entry for messages, while the ignoring type tells the extension whether to ignore messages from larger entities containing the player.

In addition, for each separate subtable required, we need to define a table following the form of:

	Table of Example Atmospheric Definition
	during	initch		latch		aftcnt		curcnt		sctype		runtype		frtype		igtype		subtable
	a scene	a number	a number	a number	a number	a scenic type	a running type	a further type	an ignoring type		a table-name

Where the during entry is the name of the scene during which the messages from the subtable will be displayed (or empty for any time), initch is the initial chance of displaying messasges, latch is the later chance for displaying messages, aftcnt is the number of messages to show before changing from the initial chance to the later chance, curcnt is the current amount of messages shown, sctype is the scenic type of the messages to be shown, runtype the running type, frtype the further type, igtype the ignoring type and finally subtable contains the name of the table from which the messages will be picked.

If any of these entries except the during entry and the subtable entry are missing, they will be initialized automatically. The initial chance to 100 percent, the later chance to the initial chance, the after count to 0, the scenic type to random, the running type to run forever, the further type to stopping and the ignoring type to do not ignore. If the subtable is the Table of Default Messages, the running type is automatically set to run forever and the further type to stopping. The current count is always initialized to 0. If there is no subtable entry, the whole row is ignored.

For each separate table of messages required, we also need to define a table according to the following specification:

	Table of Example Messages
	used		message
	a number	text

In addition, we may need to continue the Table of Messages to Show, in case there may be more than 20 messages to show at one time. This is done as follows:

	Table of Messages to Show (continued)
	message
	with <number> blank rows

*** THE TABLES DEFINED ***

This extension provides a few tables of its own, each one empty except for one blank row to contrain the contents of the table. We have already encountered one of these, the Table of Atmospheric Definition, which is used to initialize the locations and regions of the game world with the correct scenic messasges.

The second one is the Table of Default Atmospherics. If we fill this table up with information, the messages of any subtables of it will be shown in any room or region not mentioned in the Table of Atmospheric Definition.

We are also provided with the Table of Default Messages, which can be filled with messages to be used when the further type of some messasge source is default and all the messages in the original table of messages have been shown.

Also, the extension brings us the Table of Messages to Show, which is used to collect the messages to be displayed during one turn. The default size of the table is 20 rows, which may be increased if necessary.

*** OVERRIDING ***

If necessary, we can override the scenic messaging rules by creating a procedural rule to substitute a rule of our own making for the scenic messaging rule provided by this extension:

	Procedural rule:
		substitute own messaging rule for the scenic messaging rule.

The scenic messaging rule provided by the extension is defined as follows:

	Before reading a command (this is the scenic messaging rule):
		correct synonyms;
		check thing messages;
		check room messages;
		check region messages;
		display all messages.

This rule has been defined as a before reading a command rule, so that the first messages will be shown before reading the first command in the game.

*** INTERNALS ***

The extension defines a kind of value called shown type used on regions. It is highly recommended that it not be used by anyone.

The extension also defines a region called the empty region. It is used by the extension to manage looking through regions.

*** EXAMPLES ***

Example: * Forest and Clearing - A simple example of regional and room effects, and ignoring messages.

	"Forest and Clearing"

	Include Version 4/060624 of Atmospheric Effects by Mikael Segercrantz.

	Western Edge of the Forest is a room. East of the western edge of the forest is a room called A Forest Clearing. East of a forest clearing is a room called Eastern Edge of the Forest.

	The Forest Region is a region. Western edge of the forest, a forest clearing and eastern edge of the forest are in the forest region.

	Table of Atmospheric Definition (continued)
	loci			ignoring		subtable
	A Forest Clearing		ignore		Table of Clearing Definition
	Forest Region		do not ignore	Table of Forest Definition

	Table of Clearing Definition
	during		initch	latch		aftcnt		curcnt		sctype		runtype		frtype		igtype		subtable
	a scene		50	a number	a number	a number	fully random	a running type	a further type	an ignoring type	Table of Clearing Atmosphere

	Table of Clearing Atmosphere
	used		message
	a number	"The sound of a small river running nearby reaches your ear."
	--		"A cuckoo can be heard not far away." 

	Table of Forest Definition
	during		initch	latch	aftcnt	curcnt		sctype	runtype		frtype		igtype		subtable
	a scene		75	33	5	a number	random	a running type	a further type	an ignoring type	Table of Forest Region Atmosphere

	Table of Forest Region Atmosphere
	used		message
	a number	"A fox runs across the path."
	--		"Birds chirp off in the distance."
	--		"A rabbit bounces off with sudden haste."

Example: ** City and Neighborhood - A more complex example on using Atmospheric Effects on rooms and regions, with regions contained in other regions.

	"City and Neighborhood"

	Include Version 4/060624 of Atmospheric Effects by Mikael Segercrantz.

	Tower Street North is a room. Tower Street South is a room. Tower Street Middle is a room.
	Tower Street North is north of Tower Street Middle.
	Tower Street Middle is north of Tower Street South.
	The Tower Neighborhood is a region. Tower Street North, Tower Street South and Tower Street Middle are in the Tower Neighborhood.

	Main Street West is a room. Main Street Middle is a room. Main Street East is a room.
	Main Street West is west of Main Street Middle.
	Main Street Middle is west of Main Street East.
	The Main Neighborhood is a region. Main Street West, Main Street East and Main Street Middle are in the Main Neighborhood.

	Madden Park is a room.
	Madden Park is east of Main Street East.
	Madden Park is west of Tower Street Middle.

	The City is a region. Madden Park, the Main Neighborhood and the Tower Neighborhood are in the City.

	The player is in Main Street West.

	Table of Atmospheric Definition (continued)
	loci			ignoring		subtable
	Madden Park		ignore		Table of Madden Park Definition
	Tower Neighborhood	ignore		Table of Tower Neighborhood Definition
	City			do not ignore	Table of City Definition

	Table of Madden Park Definition
	during	initch	latch	aftcnt		curcnt		sctype	runtype		frtype		igtype		subtable
	a scene	100	0	a number	a number	random	run forever	a further type	an ignoring type	Table of Park Sounds

	Table of Park Sounds
	used		message
	a number	"Birds chirp off in the trees."
	--		"The fountain unleashes a gush of water."
	--		"A man sitting atop a lawn-mover is taking care of the grass."

	Table of Tower Neighborhood Definition
	during	initch	latch	aftcnt		curcnt		sctype	runtype		frtype		igtype		subtable
	a scene	100	0	a number	a number	ordered	run forever	a further type	an ignoring type	Table of Tower Neighborhood Sounds

	Table of Tower Neighborhood Sounds
	used		message
	a number	"You hear nothing but the peace and quiet of the Tower Neighborhood."
	--		"Some small children run towards Madden Park."
	--		"The neighborhood is quiet, and peace prevails."
	--		"Some children enter the neighborhood from the park nearby."

	Table of City Definition
	during	initch	latch		aftcnt		curcnt		sctype		runtype		frtype		igtype		subtable
	a scene	75	a number	a number	a number	fully random	run forever	a further type	an ignoring type		Table of City Noise

	Table of City Noise
	used		message
	a number	"Many cars pass by, making for a loud noise level."
	--		"A car screeches to a halt as a pedestrian carelessly walks onto the street."
	--		"Sires can be heard in the distance, coming your way."

Example: **** The City-Plane of Union - Showing how to use the Atmospheric Effects extension using as a setting the City-Plane of Union from the Epic Level Handbook for the latest edition of AD&D.

	"The City-Plane of Union"

	Include Version 4/060624 of Atmospheric Effects by Mikael Segercrantz.

	Use full-length room descriptions and the serial comma.

	Part 1 - Geography

	Chapter 1(a) - Planar Gate

	Planar Gate is a room.

	Planar Gate Region is a region. The planar gate is in the planar gate region.

	Chapter 1(b) - Temple Quarter

	Northwest Temple Quarter is a room. South of northwest temple quarter is a room called Southwest Temple Quarter. East of southwest temple quarter is a room called East Temple Quarter. It is southeast of northwest temple quarter.

	Temple Quarter Region is a region. Northwest temple quarter, southwest temple quarter and east temple quarter are in the temple quarter region.

	Chapter 1(c) - Material Gate

	Material Gate is a room.

	Material Gate Region is a region. The material gate is in the material gate region.

	Chapter 1(d) - Military Quarter

	South Military Quarter is a room. North of south military quarter is a room called North Military Quarter.

	Military Quarter Region is a region. North military quarter and south military quarter are in the military quarter region.

	Chapter 1(e) - High Quarter

	Southeast High Quarter is a room. Northwest of southeast high quarter is a room called Northwest High Quarter.

	High Quarter Region is a region. Southeast high quarter and northwest high quarter are in the high quarter region.

	Chapter 1(f) - Commerce Quarter

	Northwest Commerce Quarter is a room. South of northwest commerce quarter is a room called Southwest Commerce Quarter. East of northwest commerce quarter is a room called Northeast Commerce Quarter. It is northeast of southwest commerce quarter. South of northeast commerce quarter is a room called Southeast Commerce Quarter. It is east of southwest commerce quarter and southeast of northwest commerce quarter.

	Commerce Quarter Region is a region. Northwest commerce quarter, southwest commerce quarter, northeast commerce quarter and southeast commerce quarter are in the commerce quarter region.

	Chapter 1(g) - Market Quarter

	Northwest Market Quarter is a room. South of northwest market quarter is a room called Southwest Market Quarter. East of southwest market quarter is a room called South Market Quarter. It is southeast of northwest market quarter. North of south market quarter is a room called North Market Quarter. It is northeast of southwest market quarter and east of northwest market quarter. East of north market quarter is a room called Northeast Market Quarter. It is northeast of south market quarter. South of northeast market quarter is a room called Central Southeast Market Quarter. It is southeast of north market quarter and east of south market quarter. East of central southeast market quarter is a room called Southeast Market Quarter. It is southeast of northeast market quarter.

	Market Quarter Region is a region. Northwest market quarter, southwest market quarter, north market quarter, south market quarter, northeast market quarter, central southeast market quarter and southeast market quarter are in the market quarter region.

	Chapter 1(h) - Magic Quarter

	West Magic Quarter is a room. East of west magic quarter is a room called East Magic Quarter.

	Magic Quarter Region is a region. West magic quarter and east magic quarter are in the magic quarter region.

	Chapter 1(i) - Perfumed Quarter

	Southwest Perfumed Quarter is a room. East of southwest perfumed quarter is a room called Southeast Perfumed Quarter. North of southwest perfumed quarter is a room called North Perfumed Quarter. It is northwest of southeast perfumed quarter.

	Perfumed Quarter Region is a region. Southwest perfumed quarter, southeast perfumed quarter and north perfumed quarter are in the perfumed quarter region.

	Chapter 1(j) - Tavern Quarter

	East Tavern Quarter is a room. West of east tavern quarter is a room called West Tavern Quarter.

	Tavern Quarter Region is a region. East tavern quarter and west tavern quarter are in the tavern quarter region.

	Chapter 1(k) - Guild Quarter

	Southeast Guild Quarter is a room. Northwest of southeast guild quarter is a room called Northwest Guild Quarter.

	Guild Quarter Region is a region. Southeast guild quarter and northwest guild quarter are in the guild quarter region.

	Chapter 1(l) - Staircase Gate

	Staircase Gate is a room.

	Staircase Gate region is a region. Staircase gate is in the staircase gate region.

	Chapter 1(m) - Bridges

	Planar-Temple Bridge is a room. It is south of planar gate and north of northwest temple quarter.

	Planar-Material Bridge is a room. It is north of planar gate and south of material gate.

	Planar-Commerce Bridge is a room. It is northeast of planar gate and southwest of southwest commerce quarter.

	Temple-Market Bridge is a room. It is northeast of east temple quarter and southwest of southwest market quarter.

	Material-Military Bridge is a room. It is north of material gate and south of south military quarter.

	Material-Commerce Bridge is a room. It is east of material gate and west of southwest commerce quarter.

	Military-High Bridge is a room. It is northwest of north military quarter and southeast of southeast high quarter.

	Military-Commerce Bridge is a room. It is southeast of south military quarter and northwest of northwest commerce quarter.

	Commerce-Market Bridge is a room. It is south of southeast commerce quarter and north of northwest market quarter.

	Market-Magic Bridge is a room. It is north of northeast market quarter and south of west magic quarter.

	Commerce-Magic Bridge is a room. It is southeast of northeast commerce quarter and northwest of west magic quarter.

	Magic-Perfumed Bridge is a room. It is northeast of east magic quarter and southwest of southwest perfumed quarter.

	Magic-Staircase Bridge is a room. It is north of east magic quarter and south of staircase gate.

	Commerce-Guild Bridge is a room. It is north of northeast commerce quarter and south of southeast guild quarter.

	Guild-Tavern Bridge is a room. It is northeast of southeast guild quarter and southwest of west tavern quarter.

	Tavern-Staircase Bridge is a room. It is southeast of west tavern quarter and northwest of staircase gate.

	Tavern-Perfumed-Staircase Bridge is a room. It is east of east tavern quarter, north of staircase gate and west of north perfumed quarter.

	Chapter 1(n) - The City-Plane

	City-Plane of Union is a region. Planar-temple bridge, planar-commerce bridge, planar-material bridge, temple-market bridge, material-military bridge, material-commerce bridge, military-high bridge, military-commerce bridge, commerce-market bridge, market-magic bridge, commerce-magic bridge, magic-perfumed bridge, magic-staircase bridge, commerce-guild bridge, guild-tavern bridge, tavern-staircase bridge, tavern-perfumed-staircase bridge, planar gate region, material gate region, military quarter region, high quarter region, temple quarter region, commerce quarter region, market quarter region, magic quarter region, perfumed quarter region, tavern quarter region, guild quarter region and staircase gate region are in the city-plane of union.

	Chapter 1(o) - Objects

	A gushing fountain is in southwest commerce quarter. It is fixed in place.

	Part 2 - Atmospherics

	Chapter 2(a) - Full City-Plane

	Table of City-Plane of Union Definition
	during		initch	latch	aftcnt	curcnt	sctype		runtype		frtype		igtype		subtable
	Arrival		100	33	1	0	ordered		run once	stopping		do not ignore	Table of Arrival Messages
	Encounters	50	50	0	0	random		run forever	stopping		do not ignore	Table of Encounter Messages

	Table of Arrival Messages
	used	message
	0	"The sudden bustling of activity as you enter the City-Plane of Union almost overwhelmes you."
	0	"You are slowly, ever so slowly, getting used to the bustling of activities ."
	0	"The bustling activities continue as usual, but you are getting more and more acclimatized to them."
	0	"Suddenly, you realize you no longer notice anything unusal about all the activities going on around you."

	Table of Encounter Messages
	used	message
	0	"A patrol of Union City guards stop to question people."
	0	"In the distance, you can see a patrol of guards coming closer to you."
	0	"You are stopped by a patrol of Union City guards and asked for your papers. You show the papers to them."
	0	"A mercane is looking at you, squinting [if a random chance of 1 in 2 succeeds]his[otherwise]her[end if] eyes."

	Chapter 2(b) - Specific things

	Table of Gushing Fountain Definition
	during	initch	latch	aftcnt	curcnt	sctype		runtype			frtype		igtype		subtable
	--	100	100	0	0	random		run forever		stopping		do not ignore	Table of Gushing Fountain Messages

	Table of Gushing Fountain Messages
	used	message
	0	"The fountain unleases a gush of water, at least 20 feet high."
	0	"You hear a gurgling sound from the fountain, as it sucks in water from the pool."
	0	"A glimmer of gold catches your eye, deep in the pool of the fountain."
	0	"The constant stream of water from the fountain flies about the area as a gust of wind arrives."

	Chapter 2(c) - The Stairway Gate

	Table of Stairway Gate Definition
	during	initch	latch	aftcnt	curcnt	sctype		runtype			frtype		igtype		subtable
	--	100	50	2	0	random		run forever		stopping		do not ignore	Table of Stairway Gate Messages

	Table of Stairway Gate Messages
	used	message
	0	"People come in and leave through the Stairway Gate to the Infinite Stairway."
	0	"The bustling of people travelling through the Stairway Gate is awe-inspring."

	Chapter 2(d) - Definition

	Table of Atmospheric Definition (continued)
	loci				ignoring			subtable
	City-Plane of Union		do not ignore		Table of City-Plane of Union Definition
	gushing fountain			do not ignore		Table of Gushing Fountain Definition
	Staircase Gate			do not ignore		Table of Stairway Gate Definition

	Part 3 - Scenes

	Chapter 3(a) - Arrival

	Arrival is a scene. Arrival begins when play begins. Arrival ends when the number of filled rows in the Table of Arrival Messages is 0.

	Chapter 3(b) - Encounters

	Encounters is a scene. Encounters begins when Arrival ends.

	Part 4 - Modifications

	Chapter 4(a) - Room

	The description of a room is usually "[exit list]".

	To say exit list:
		let count be 0;
		repeat with d running through directions
		begin;
			let r be the room d from the location;
			if r is a room,
				increase count by 1;
		end repeat;
		if the count is 0
		begin;
			say "You appear to be trapped in here.";
		otherwise;
			if the count is 1,
				say "From here, the only way is";
			otherwise
				say "From here, the viable exits are";
			let original be count;
			repeat with d running through directions
			begin;
				let r be the room d from the location;
				if r is a room
				begin;
					say " [d] to [r]";
					decrease count by 1;
					if count is 1
					begin;
						if original is 2, say " and";
						otherwise say "[optional comma] and";
					otherwise;
						if count is 0, say ".";
						otherwise say ",";
					end if;
				end if;
			end repeat;
		end if.

	To say optional comma:
		if using the serial comma option, say ",".

	Chapter 4(b) - Status line

	When play begins:
		change the left hand status line to "[map region of the location]";
		change the right hand status line to "[number of visited rooms]/[number of rooms]".

	Part 5 - Starting and ending the game

	Chapter 5(a) - Starting

	When play begins:
		say "What happenstance.

	You have been trying to reach this place for the last few years, and suddenly, you find yourself here.

	In... The City-Plane of Union.

	Now, you want to find out everything there is to know about the place. Thankfully, you've memorized the map of the place.[line break](To win, visit every room and see every message)[paragraph break]".

	Chapter 5(b) - Ending

	Every turn:
		let total be 0;
		repeat with n running from 1 to the number of rows in the Table of Atmospheric Definition
		begin;
			choose row n in the table of Atmospheric Definition;
			if there is a subtable entry
			begin;
				let tbl be the subtable entry;
				repeat with o running from 1 to the number of rows in tbl
				begin;
					choose row o in tbl;
					if there is a subtable entry
					begin;
						if the runtype entry is ordered or the runtype entry is random
						begin;
							let c be the curcnt entry;
							let d be the number of filled rows in the subtable entry;
							let e be d minus c;
							if e is less than 0, change e to 0;
							increase total by e;
						otherwise;
							let lbt be the subtable entry;
							repeat with p running from 1 to the number of rows in lbt
							begin;
								if there is a message entry
								begin;
									if the used entry is 0, increase total by 1;
								end if;
							end repeat;
						end if;
					end if;
				end repeat;
			end if;
		end repeat;
		increase total by the number of rooms;
		decrease total by the number of visited rooms;
		if total is 0, end the game saying "You have visited all rooms and seen all messages".
